<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #app {
        width: 100%;
        display: flex;
        justify-content: center;
      }

      .block {
        width: max-content;
      }

      .block .input-msg {
        margin-bottom: 10px;
      }

      table {
        width: 500px;
        border-collapse: collapse;
      }

      tr td,
      tr th {
        border: 1px solid green;
        padding: 10px 0 10px 0;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="block">
        <div class="input-msg">
          <input type="text" v-model="name" placeholder="请输入姓名" />
        </div>
        <div>
          <table id="tableMsg">
            <tr>
              <th>学号</th>
              <th>姓名</th>
              <th>性别</th>
              <th>联系方式</th>
              <th style="cursor: pointer">年龄</th>
            </tr>
            <tr v-for="item in student" :key="item.id">
              <td>{{ item.id }}</td>
              <td>{{ item.name }}</td>
              <td>{{ item.sex }}</td>
              <td>{{ item.tel }}</td>
              <td>{{ item.age }}</td>
            </tr>
          </table>
        </div>
      </div>
    </div>
    <script src="./vue.js"></script>
    <script>
      let app = new Vue({
        el: "#app",
        data: {
          name: "",
          msg: [
            {
              id: 1,
              name: "大春",
              sex: "男",
              place: "青海",
              tel: "13412345678",
              age: 20,
            },
            {
              id: 2,
              name: "珊珊",
              sex: "女",
              place: "青海",
              tel: "13447445678",
              age: 18,
            },
            {
              id: 3,
              name: "纯纯",
              sex: "女",
              place: "青海",
              tel: "13412585678",
              age: 11,
            },
            {
              id: 4,
              name: "大华",
              sex: "男",
              place: "青海",
              tel: "13412311278",
              age: 25,
            },
            {
              id: 5,
              name: "小龙",
              sex: "男",
              place: "青海",
              tel: "13412665878",
              age: 30,
            },
            {
              id: 6,
              name: "小六",
              sex: "男",
              place: "青海",
              tel: "13412665878",
              age: 30,
            },
          ],
        },
        computed: {
          student() {
            return this.msg.filter((item) => {
              if (item.name.match(this.name)) {
                return item;
              }
            });
          },
        },
      });
    </script>
  </body>
</html>
